package com.bjpowernode.controller;

import com.bjpowernode.model.TUser;
import com.bjpowernode.result.R;
import com.bjpowernode.util.JSONUtil;
import com.bjpowernode.util.JWTUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    /**
     * 免登录
     *
     * @return
     */
    @GetMapping(value = "/api/freeLogin")
    public R freeLogin() {
        return R.OK();
    }

    /**
     * 获取当前登录人信息
     *
     * @param jwt
     * @return
     */
    @GetMapping(value = "/api/login/info")
    public R loginInfo(@RequestHeader(value = "Authorization") String jwt) {
        //反向解析一下jwt里面的负载数据即可
        String loginUserJSON = JWTUtil.parseJWT(jwt);
        TUser tUser = JSONUtil.toBean(loginUserJSON, TUser.class);
        return R.OK(tUser);
    }
    @GetMapping(value = "/api/check")
    public R check() {
        return R.OK();
    }
}
